package top.wangjiu.java.jvm.attribute;

import top.wangjiu.java.jvm.AttributeInfo;
import top.wangjiu.java.jvm.constantinfo.ConstantPoolInfo;

public class SourceFileAttr extends AttributeInfo {

    public final static String NAME = "SourceFile";

    private final short attributeNameIndex;   //属性名索引
    private final int attributeLength;
    //字段值在常量池中的索引
    private final short sourceFileIndex;

    public SourceFileAttr(short attributeNameIndex, byte[] bytes){
        this.attributeNameIndex = attributeNameIndex;
        this.attributeLength = bytes.length;
        this.sourceFileIndex = (short) (bytes[0]<<8 | bytes[1]);
    }

    @Override
    public short attributeNameIndex() {
        return attributeNameIndex;
    }

    @Override
    public int attributeLength() {
        return attributeLength;
    }

    @Override
    public String toString(ConstantPoolInfo[] poolInfos) {
        return "SourceFile:" + poolInfos[sourceFileIndex].toString(poolInfos);
    }
}
